﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FacebookApp;
using System.Data;
using System.Configuration;

public partial class Pages_ProductDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //WebMsgBox.Show(Request.Url.AbsoluteUri);
        if (!IsPostBack)
        {
            lblName.Text = "Thông tin sản phẩm";
            string s = Request.QueryString["Id"].ToString();
            List<Ebook> lst = new List<Ebook>();
            Ebook eb = EbookService.Ebook_GetById(s);
            if (eb != null)
                lst.Add(eb);
            dlChiTietSanPham.DataSource = lst;
            dlChiTietSanPham.DataBind();

            EbookService.Ebook_Update_NumView(s);
        }
    }

    protected void dlChiTietSanPham_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Choose")
        {
            AddCart(Request.QueryString["Id"].ToString(), "1");
        }
    }

    protected void AddCart(string productid, string quantity)
    {
        if (Session["Cart"] == null)
            Session["Cart"] = FunctionClass.AddCart(productid, quantity, null);
        else
            Session["Cart"] = FunctionClass.AddCart(productid, quantity, (DataTable)Session["Cart"]);
    }

    public string Format_Price(string s)
    {
        return FunctionClass.Format_Price(s);
    }

    public string Price(string s)
    {
        if(s=="0 VNĐ")
            return "";
        else
            return "&nbsp;&nbsp;&nbsp;Giá khuyến mại: " + s;
    }

    //public string IsVAT(int Values)
    //{
    //    if (Values == 0)
    //        return "Giá trên chưa bao gồm VAT";
    //    return "Giá trên đã bao gồm VAT";
    //}
    public string Quantity(string Value)
    {
        if (int.Parse(Value) == 0)
            return "Đã hết hàng trong kho";
        return "Còn <span style=\"color: #133783; \">" + Value + " </span>sản phẩm trong kho";
    }

    public string url(string Id)
    {
        //string s = "https://www.facebook.com/plugins/comments.php?api_key=290146691073914&amp;channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D6%23cb%3Df593c5c2%26origin%3Dparent.parent&amp;"
        //    + "http://apps.facebook.com/e_store/Pages/"+Id+"/ProductDetail.aspx?Id=" + Id + ";"
        //    + "locale=en_US&amp;numposts=10&amp;sdk=joey&amp;width=550";
       // string s = ConfigurationSettings.AppSettings["fb_domain"].ToString() + "";
        string s = "http://www.fbapps.somee.com/" + "Pages/ProductDetail.aspx?Id=" + Id;
        return s;
    }

    public string urllike(string Id)
    {
        //string s = "https://www.facebook.com/plugins/comments.php?api_key=290146691073914&amp;channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D6%23cb%3Df593c5c2%26origin%3Dparent.parent&amp;"
        //    + "http://apps.facebook.com/e_store/Pages/"+Id+"/ProductDetail.aspx?Id=" + Id + ";"
        //    + "locale=en_US&amp;numposts=10&amp;sdk=joey&amp;width=550";
        // string s = ConfigurationSettings.AppSettings["fb_domain"].ToString() + "";
        string s = ConfigurationSettings.AppSettings["fb_headerpath"].ToString() + "Pages/ProductDetail.aspx?Id=" + Id;
        return s;
    }
        
}